﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using UCNKompetenceBors.Model;

namespace UCNKompetenceBors.Database
{
    public class dbAdmin
    {
        #region Exchange
        /// <summary>
        /// Gets a list of all purchases, based on input parameters.
        /// </summary>
        /// <param name="timespan">Specifies which timespan the results should be in.</param>
        /// <param name="categoryId">Specifies which category the results should be in.</param>
        /// <param name="search">Specifies a string to search for in the title and description of the results.</param>
        /// <returns>Returns a list of Purchase objects</returns>
        public static List<Purchase> GetAllPurchases(int timespan, int categoryId = 0, string search = null)
        {
            return dbExchange.GetAllPurchases(timespan, categoryId, search);
        }

        /// <summary>
        /// Gets a list of all sales, based on input parameters.
        /// </summary>
        /// <param name="timespan">Specifies which timespan the results should be in.</param>
        /// <param name="categoryId">Specifies which category the results should be in.</param>
        /// <param name="search">Specifies a string to search for in the title and description of the results.</param>
        /// <returns>Returns a list of Sale objects</returns>
        public static List<Sale> GetAllSales(int timespan, int categoryId = 0, string search = null)
        {
            return dbExchange.GetAllSales(timespan, categoryId, search);
        }

        /// <summary>
        /// Deletes a purchase, based on the purchaseId parameter.
        /// </summary>
        /// <param name="purchaseId">Specifies the ID of the purchase to be deleted.</param>
        public static void DeletePurchase(int purchaseId)
        {
            dbExchange.DeletePurchase(purchaseId);
        }

        /// <summary>
        /// Deletes a sale, based on the saleId parameter.
        /// </summary>
        /// <param name="saleId">Specifies the ID of the sale to be deleted.</param>
        public static void DeleteSale(int saleId)
        {
            dbExchange.DeleteSale(saleId);
        }

        /// <summary>
        /// Gets a list of all categories.
        /// </summary>
        /// <returns>Returns a list of Category objects.</returns>
        public static List<Category> GetAllCategories()
        {
            return dbExchange.GetAllCategories();
        }

        /// <summary>
        /// Updates a category, based on the input parameters.
        /// </summary>
        /// <param name="categoryID">Specifies the ID of the category to be updated.</param>
        /// <param name="categoryName">Specifies the category name to be used in the update.</param>
        /// <param name="localizedCategoryName">Specifies the localized category name to be used in the update.</param>
        public static void UpdateCategory(int categoryId, string categoryName, string localizedCategoryName)
        {
            dbExchange.UpdateCategory(categoryId, categoryName, localizedCategoryName);
        }

        /// <summary>
        /// Deletes a category, based on the categoryId.
        /// </summary>
        /// <param name="categoryId">Specifies the ID of the category to be deleted.</param>
        public static void DeleteCategory(int categoryId)
        {
            dbExchange.DeleteCategory(categoryId);
        }

        /// <summary>
        /// Creates a category, based on the input parameters.
        /// </summary>
        /// <param name="categoryName">Specifies the name of the category to be created.</param>
        /// <param name="localizedCategoryName">Specifies the localized name of the category to be created.</param>
        public static void CreateCategory(string categoryName, string localizedCategoryName)
        {
            dbExchange.CreateCategory(categoryName, localizedCategoryName);
        }

        /// <summary>
        /// Validates whether or not the specified category name already exists in the database.
        /// </summary>
        /// <param name="categoryName">Specifies the name of the category to be validated.</param>
        /// <returns>Returns a bool specifying whether or not the specified category name already exists in the database.</returns>
        public static bool ValidateCategoryName(string categoryName)
        {
            return dbExchange.ValidateCategoryName(categoryName);
        }

        /// <summary>
        /// Validates whether or not the specified localized category name already exists in the database.
        /// </summary>
        /// <param name="localizedCategoryName">Specifies the localized name of the category to be validated.</param>
        /// <returns>Returns a bool specifying whether or not the specified localized category name already exists in the database.</returns>
        public static bool ValidateLocalizedCategoryName(string localizedCategoryName)
        {
            return dbExchange.ValidateLocalizedCategoryName(localizedCategoryName);
        }

        /// <summary>
        /// Validates whether or not the specified categoryId is in use.
        /// </summary>
        /// <param name="categoryId">Specifies the ID of the category to be validated.</param>
        /// <returns>Returns a bool specifying whether or not the specified categoryId is in use.</returns>
        public static bool ValidateCategoryUsed(int categoryId)
        {
            return dbExchange.ValidateCategoryUsed(categoryId);
        }
        #endregion

        #region Information
        /// <summary>
        /// Gets a distinct list of page IDs.
        /// </summary>
        /// <returns>Returns a list of strings containing page IDs.</returns>
        public static List<string> GetInformationPageIds()
        {
            return dbInformation.GetPageIdsDistinct();
        }

        /// <summary>
        /// Gets a list of control IDs, based on the pageId parameter.
        /// </summary>
        /// <param name="pageId">Specifies the ID of the page to be used.</param>
        /// <returns>Returns a list of strings containing control IDs.</returns>
        public static List<Information> GetInformationControls(string pageId)
        {
            return dbInformation.GetControlsByPageId(pageId);
        }

        /// <summary>
        /// Gets a text, based on the pageId and controlId parameters.
        /// </summary>
        /// <param name="pageId">Specifies the ID of the page to be used.</param>
        /// <param name="controlId">Specifies the ID of the control to be used.</param>
        /// <returns>Returns a string containing the resulting text.</returns>
        public static string GetInformationText(string pageId, string controlId)
        {
            return dbInformation.GetInformationByPageIdAndControlId(pageId, controlId);
        }

        /// <summary>
        /// Updates the information, based on the input parameters.
        /// </summary>
        /// <param name="informationText">Specifies the text to be used.</param>
        /// <param name="controlId">Specifies the ID of the control to be used.</param>
        /// <param name="pageId">Specifies the ID of the page to be used.</param>
        public static void UpdateInformation(string informationText, string controlId, string pageId)
        {
            dbInformation.UpdateInformation(informationText, controlId, pageId);
        }
        #endregion

        #region News
        /// <summary>
        /// Gets a list of all news articles.
        /// </summary>
        /// <returns>Returns a list of News objects.</returns>
        public static List<News> GetAllNews()
        {
            return dbNews.GetAllNews();
        }

        /// <summary>
        /// Deletes a news article, based on the newsId parameter.
        /// </summary>
        /// <param name="newsId">Specifies the ID of the news article to be deleted.</param>
        public static void DeleteNews(int newsId)
        {
            dbNews.DeleteNews(newsId);
        }

        /// <summary>
        /// Checks whether or not a news article has an image, based on the newsId parameter.
        /// </summary>
        /// <param name="newsId">Specifies the ID of the news article to be used.</param>
        /// <returns>Returns a boolean, specifying whether or not a news article has an image.</returns>
        public static bool NewsHasImage(int newsId)
        {
            return dbNews.NewsHasImage(newsId);
        }

        /// <summary>
        /// Creates a news article, based on the input parameters.
        /// </summary>
        /// <param name="title">Specifies the title to be used.</param>
        /// <param name="text">Specifies the text to be used.</param>
        /// <param name="hasImage">Specifies whether or not news article has an image.</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>
        /// <param name="culture">Specifies the culture to be used in the localized news article.</param>
        /// <param name="locTitle">Specifies the title to be used in the localized news article.</param>
        /// <param name="locText">Specifies the text to be used in the localized news article.</param>
        public static void CreateNews(string title, string text, bool hasImage, string imageFileName, string culture, string locTitle, string locText)
        {
            dbNews.CreateNews(title, text, hasImage, imageFileName, culture, locTitle, locText);
        }

        /// <summary>
        /// Gets a news article, based on the newsId parameter.
        /// </summary>
        /// <param name="newsId">Specifies the ID of the news article to be retrieved.</param>
        /// <returns>Returns a News object.</returns>
        public static News GetNewsById(int newsId)
        {
            return dbNews.GetNewsById(newsId);
        }

        /// <summary>
        /// Edits a news article, based on the newsId parameter.
        /// </summary>
        /// <param name="title">Specifies the title to be used.</param>
        /// <param name="text">Specifies the text to be used.</param>
        /// <param name="hasImage">Specifies whether or not news article has an image.</param>
        /// <param name="imagePath">Specifies the path of the current image.</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>
        /// <param name="newsId">Specifies the ID of the news article to be used.</param>
        /// <param name="locTitle">Specifies the title to be used in the localized news article.</param>
        /// <param name="locText">Specifies the text to be used in the localized news article.</param>
        public static void EditNews(string title, string text, bool hasImage, string imagePath, string imageFileName, int newsId, string locTitle, string locText)
        {
            dbNews.EditNews(title, text, hasImage, imagePath, imageFileName, newsId, locTitle, locText);
        }
        #endregion

        #region ContactPerson
        /// <summary>
        /// Gets a list of all contact persons.
        /// </summary>
        /// <returns>Returns a list of ContactPerson objects.</returns>
        public static List<ContactPerson> GetAllContactPersons()
        {
            return dbContactPerson.GetAllContactPersons();
        }

        /// <summary>
        /// Gets a contact person, based on the contactPersonId parameter.
        /// </summary>
        /// <param name="contactPersonId">Specifies the ID of the contact person to be retrieved.</param>
        /// <returns>Returns a ContactPerson object.</returns>
        public static ContactPerson GetContactPersonById(int contactPersonId)
        {
            return dbContactPerson.GetContactPersonById(contactPersonId);
        }

        /// <summary>
        /// Creates a contact person, based on the input parameters.
        /// </summary>
        /// <param name="fName">Specifies the first name to be used.</param>
        /// <param name="lName">Specifies the last name to be used.</param>
        /// <param name="hasImage">Specifies whether or not contact person has an image.</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>
        /// <param name="phone">Specifies the phone to be used in the contact person.</param>
        /// <param name="email">Specifies the email to be used in the contact person.</param>
        /// <param name="title">Specifies the title to be used in the contact person.</param>
        /// <param name="department">Specifies the department to be used in the contact person</param>
        public static void CreateContactPerson(string fName, string lName, bool hasImage, string imageFileName, string phone, string email, string title, string department)
        {
            dbContactPerson.CreateContactPerson(fName, lName, hasImage, imageFileName, phone, email, title, department);
        }

        /// <summary>
        /// Deletes a contact person, based on the contactPersonId parameter.
        /// </summary>
        /// <param name="contactPersonId">Specifies the ID of the contact person to be deleted.</param>
        public static void DeleteContactPerson(int contactPersonId)
        {
            dbContactPerson.DeleteContactPerson(contactPersonId);
        }

        /// <summary>
        /// Checks whether or not a contact person has an image, based on the contactPersonId parameter.
        /// </summary>
        /// <param name="contactPersonId">Specifies the ID of the contact person to be used.</param>
        /// <returns>Returns a boolean, specifying whether or not a contact person has an image.</returns>
        public static bool ContactPersonHasImage(int contactPersonId)
        {
            return dbContactPerson.ContactPersonHasImage(contactPersonId);
        }

         /// <summary>
        /// Edits a contact person, based on the contactPersonId parameter.
        /// </summary>
        /// <param name="contactPersonId">Specifies the ID of the contact person to be used.</param>
        /// <param name="fName">Specifies the first name to be used.</param>
        /// <param name="lName">Specifies the last name to be used.</param>
        /// <param name="hasImage">Specifies whether or not news article has an image.</param>
        /// <param name="imagePath">Specifies the path of the current image.</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>        
        /// <param name="phone">Specifies the phone to be used.</param>
        /// <param name="email">Specifies the email to be used.</param>
        /// <param name="title">Specifies the title to be used.</param>
        /// <param name="department">Specifies the department to be used</param>
        public static void EditContactPerson(int contactPersonId, string fName, string lName, bool hasImage, string imagePath, string imageFileName, string phone, string email, string title, string department)
        {
            dbContactPerson.EditContactPerson(contactPersonId, fName, lName, hasImage, imagePath, imageFileName, phone, email, title, department);
        }

        #endregion

        #region Depatment
        /// <summary>
        /// Gets a department, based on the departmentId parameter.
        /// </summary>
        /// <param name="departmentId">Specifies the ID of the department to be retrieved.</param>
        /// <returns>Returns a Department object.</returns>
        public static Department GetDepartmentById(int departmentId)
        {
            return dbDepartment.GetDepartmentById(departmentId);
        }

        // <summary>
        /// Gets a list of all departments.
        /// </summary>
        /// <returns>Returns a list of Department objects.</returns>
        public static List<Department> GetAllDepartments()
        {
            return dbDepartment.GetAllDepartments();
        }

        /// <summary>
        /// Creates a department, based on the input parameters.
        /// </summary>
        /// <param name="name">Specifies the department name to be used.</param>
        /// <param name="hasImage">Specifies whether or not contact person has an image.</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>
        /// <param name="address">Specifies the address to be used.</param>
        /// <param name="zipCode">Specifies the zip code to be used.</param>
        /// <param name="city">Specifies the city to be used.</param>
        /// <param name="email">Specifies the email to be used in the contact person.</param>
        /// <param name="phone">Specifies the phone to be used in the contact person.</param>
        /// <param name="fax">Specifies the fax to be used.</param>
        public static void CreateDepartment(string name, bool hasImage, string imageFileName, string address, string zipCode, string city, string email, string phone, string fax)
        {
            dbDepartment.CreateDepartment(name, hasImage, imageFileName, address, zipCode, city, email, phone, fax);
        }

        /// <summary>
        /// Deletes a department, based on the departmentId parameter.
        /// </summary>
        /// <param name="departmentId">Specifies the ID of the department to be deleted.</param>
        public static void DeleteDepartment(int departmentId)
        {
            dbDepartment.DeleteDepartment(departmentId);
        }

        /// <summary>
        /// Checks whether or not a department has an image, based on the departmentId parameter.
        /// </summary>
        /// <param name="departmentId">Specifies the ID of the department to be used.</param>
        /// <returns>Returns a boolean, specifying whether or not a department has an image.</returns>
        public static bool DepartmentHasImage(int departmentId)
        {
            return dbDepartment.DepartmentHasImage(departmentId);
        }

        /// <summary>
        /// Edits a department, based on the departmentId parameter.
        /// </summary>
        /// <param name="departmentId">Specifies the ID of the department to be used.</param>
        /// <param name="name">Specifies the department name to be used.</param>
        /// <param name="hasImage">Specifies whether or not contact person has an image.</param>
        /// <param name="imagePath">Specifies the path to the image</param>
        /// <param name="imageFileName">Specifies the file name of the image to be used.</param>
        /// <param name="address">Specifies the address to be used.</param>
        /// <param name="zipCode">Specifies the zip code to be used.</param>
        /// <param name="city">Specifies the city to be used.</param>
        /// <param name="email">Specifies the email to be used in the contact person.</param>
        /// <param name="phone">Specifies the phone to be used in the contact person.</param>
        /// <param name="fax">Specifies the fax to be used.</param>
        public static void EditDepartment(int departmentId, string name, bool hasImage, string imagePath, string imageFileName, string address, string zipCode, string city, string email, string phone, string fax)
        {
            dbDepartment.EditDepartment(departmentId, name, hasImage, imagePath, imageFileName, address, zipCode, city, email, phone, fax);
        }
        #endregion

        #region User
        /// <summary>
        /// Gets a list of all users.
        /// </summary>
        /// <returns>Returns a list of LoginUser objects.</returns>
        public static List<LoginUser> GetAllUsers()
        {
            return dbLogin.GetAllUsers();
        }

        /// <summary>
        /// Deletes a user based on the userId and userName parameters.
        /// </summary>
        /// <param name="userId">Specifies the ID of the user to be deleted.</param>
        /// <param name="userName">Specifies the user name of the user to be deleted.</param>
        public static void DeleteUser(Guid userId, string userName)
        {
            dbLogin.DeleteUser(userId, userName);
        }

        /// <summary>
        /// Adds profile information to an already existing user, based on the input parameters.
        /// </summary>
        /// <param name="userName">Specifies the user name to be used.</param>
        /// <param name="firstName">Specifies the first name to be used.</param>
        /// <param name="lastName">Specifies the last name to be used.</param>
        /// <param name="phone">Specifies the phone to be used.</param>
        /// <param name="bio">Specifies the biography to be used.</param>
        public static void AddProfileInformation(string userName, string firstName, string lastName, string phone, string bio)
        {
            dbLogin.AddProfileInformation(userName, firstName, lastName, phone, bio);
        }

        /// <summary>
        /// Gets a user, based on the userId parameter.
        /// </summary>
        /// <param name="userId">Specifies the ID of the user to be retrieved.</param>
        /// <returns>Returns a LoginUser object.</returns>
        public static LoginUser GetUserById(Guid userId)
        {
            return dbLogin.GetUserById(userId);
        }

        /// <summary>
        /// Edits a user, based on the input parameters.
        /// </summary>
        /// <param name="firstName">Specifies the first name to be used.</param>
        /// <param name="lastName">Specifies the last name to be used.</param>
        /// <param name="phone">Specifies the phone to be used.</param>
        /// <param name="bio">Specifies the biography to be used.</param>
        /// <param name="userId">Specifies the ID of the user to be edited</param>
        public static void EditUser(string firstName, string lastName, string phone, string bio, Guid userId)
        {
            dbLogin.EditUser(firstName, lastName, phone, bio, userId);
        }

        /// <summary>
        /// Marks users for deletion. 
        /// </summary>
        public static void MarkUsersForDeletion()
        {
            dbLogin.MarkUsersForDeletion();
        }

        /// <summary>
        /// Starts the reset users process, based on the input parameters.
        /// </summary>
        /// <param name="startDate">Specifies the start date to be used.</param>
        /// <param name="endDate">Specifies the end date to be used.</param>
        public static void StartResetUsers(DateTime startDate, DateTime endDate)
        {
            dbLogin.StartResetUsers(startDate, endDate);
        }

        /// <summary>
        /// Gets the startDate, endDate and status of the reset users process.
        /// </summary>
        /// <returns>Returns a ResetUsers object.</returns>
        public static ResetUsers GetResetUsers()
        {
            return dbLogin.GetResetUsers();
        }

        /// <summary>
        /// Deletes all users marked for deletion.
        /// </summary>
        public static void DeleteUsersMarkedForDeletion()
        {
            dbLogin.DeleteUsersMarkedForDeletion();
        }

        /// <summary>
        /// Creates an SQL job to delete users marked for deletion.
        /// </summary>
        /// <param name="startDate">Specifies the starting date of the SQL job.</param>
        //public static void CreateDeletionJob(DateTime startDate)
        //{
        //    dbLogin.CreateDeletionJob(startDate);
        //}
        #endregion
    }
}